<?php

class PageContent {
private $_db;

public function __construct($db=NULL)
    {
        if(is_object($db))
        {
            $this->_db = $db;
        }
        else
        {
            $dsn = "mysql:host=".DB_HOST.";dbname=".DB_NAME;
            $this->_db = new PDO($dsn, DB_USER, DB_PASS);
        }
    }
	
public function getNewBlocks() {
	$sql = "Select blocks_dir, BlocksThumb, BlocksName 
			FROM blocks";
	if($stmt = $this->_db->prepare($sql)) {
		$stmt->execute();
		while($row = $stmt->fetch()) {
			echo '<li class="als-item"><img src=\''. $row['blocks_dir']."/". $row['BlocksThumb'] .'\' alt=\''. $row['BlocksName']. '\' title=\''. $row['BlocksName'].'\' /></li>';
		}
		 $stmt->closeCursor();
	
	}
	else
		echo "Failed to retrieve blocks";

}

public function getBlockContent($dir) {
	$files = array(); 
	$directory = opendir($dir);
	while($item = readdir($directory)){
		if ($item != '.' && $item != '..' && $item != 'cover.jpg')
			$files[] = $item; 
	}
	return $files;

}

public function getBlocksSummary($blockstitle){
	$sql = "Select BlocksThumb, BlocksName, Summary, published, pages, blocks_dir, FirstName, LastName 
			FROM blocks, users
			WHERE blocksdir_name =:name AND UserID = users_UserID";
	if($stmt = $this->_db->prepare($sql)) {
		$stmt->bindParam(":name", $blockstitle, PDO::PARAM_STR);
		$stmt->execute();
		$row = $stmt->fetch();
		$stmt->closeCursor();
		return $row;
	}
	else
		return null;

}


}


?>